*** Settings ***
Library           RequestsLibrary
Resource           ../common/common.robot
Library           JSONLibrary

*** Keywords ***
Delete Goods
    [Arguments]     ${goods_id}
    Create Session    delete_goods    ${host}
    ${header}    Create Header
    ${data}    Create Dictionary    id=${goods_id}
    ${response}    POST On Session    delete_goods    /api/admin/goods/delete.ac    json=${data}    headers=${header}
    Should Be Equal As Numbers    ${response.json()['status']}    200
    Should Be Equal As Strings    ${response.json()['message']}    OK

Save Goods
    [Arguments]     ${data}
    ${header}    Create Header
    Create Session    save_good    ${host}
    ${response}    POST On Session    save_good    /api/admin/goods/insert.ac    json=${data}    headers=${header}
    Log    ${response.json()}
    Should Be Equal As Numbers    ${response.json()['status']}    200       # 校验接口状态
    ${new_goods_id}=    Get Value From JSON    ${response.json()}    $.data     # 保存新商品id
    RETURN    ${new_goods_id[0]}

Update Goods
    [Arguments]     ${data}
    ${header}    Create Header
    Create Session    update_good    ${host}
    ${response}    POST On Session    update_good    /api/admin/goods/update.ac    json=${data}    headers=${header}
    Log    ${response.json()}
    Should Be Equal As Numbers    ${response.json()['status']}    200       # 校验接口状态

Get Goods
    [Arguments]     ${goods_id}
    Create Session    get_goods    ${host}
    ${header}    Create Header
    ${data}    Create Dictionary    id=${goods_id}
    ${response}    POST On Session    get_goods   /api/admin/goods/get.ac    json=${data}    headers=${header}
    Should Be Equal As Numbers    ${response.json()['status']}    200
    Should Be Equal As Strings    ${response.json()['message']}    查询成功
    RETURN  ${response.json()['data']}

List Goods
    [Arguments]     ${data}
    Create Session    list_goods    ${host}
    ${header}    Create Header
    ${response}    POST On Session    list_goods    /api/admin/goods/queryList.ac    json=${data}    headers=${header}
    Should Be Equal As Numbers    ${response.json()['status']}    200
    Should Be Equal As Strings    ${response.json()['message']}    OK
    RETURN  ${response.json()['data']['list']}